#include <iostream>
#include <memory>
#include <pthread.h>
#include <vector>
#include <map>
#include "learn_6.hpp"

struct Address
{
    std::string city;
    std::string street;
    int number;

    REFLECT(city, street, number);
};

struct Student
{
    std::string name;
    int age;
    Address address;
    std::vector<std::string> hobbies;
    std::map<std::string, int> scores;

    REFLECT(name, age, address, hobbies, scores);
};

int main(void)
{
    Student stu = {"Tom", 20, Address{"Beijing", "Chaoyang Road", 100} , {"football", "basketball"}, {{"math", 90}, {"english", 80}}};

    std::string bin = toString(serialize(stu));
    std::cout << bin << std::endl;

    auto stu2 = deserialize<Student>(fromString(bin));
    std::cout << "name: " << stu2.name << ", age: " << stu2.age 
              << ", address: " << stu2.address.city << ", "
              << stu2.address.street << ", " << stu2.address.number << std::endl;
    std::cout << "hobbies: ";
    for (const auto& hobby : stu2.hobbies) {
        std::cout << hobby << " ";
    }
    std::cout << std::endl;
    std::cout << "scores: ";
    for (const auto& [subject, score] : stu2.scores) {
        std::cout << subject << ": " << score << " ";
    }
    std::cout << std::endl;

    return 0;
}